package cn.edu.tsinghua.mutimedia.map.job;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
import cn.edu.tsinghua.mutimedia.format.ImageInputFormat;
import cn.edu.tsinghua.mutimedia.map.audio.AudioFeatherExtractMap;
import cn.edu.tsinghua.mutimedia.map.image.ImageFeatherExtractMap;
import cn.edu.tsinghua.mutimedia.reduce.audio.AudioFeatherExtractReduce;
import cn.edu.tsinghua.mutimedia.reduce.image.ImageFeatherExtractReduce;

public class ExtractFeature  {

  public static void main(String[] args) throws Exception {
//    Configuration conf = new Configuration();
//    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
//    if (otherArgs.length != 2) {
//      System.err.println("Usage: ExtractFeature <in> <out>");
//      System.exit(2);
//    }
//    System.out.println("ExtractFeature:******************************ExtractFeature*******************************");
//    Job audioFeatherExtractJob = new Job(conf, "ExtractFeature");
//    audioFeatherExtractJob.setWorkingDirectory(new Path(otherArgs[0]));
//    audioFeatherExtractJob.setJarByClass(ExtractFeature.class);
//    audioFeatherExtractJob.setInputFormatClass(ImageInputFormat.class);
//    audioFeatherExtractJob.setMapperClass(AudioFeatherExtractMap.class);
//    audioFeatherExtractJob.setReducerClass(AudioFeatherExtractReduce.class);
//    FileInputFormat.addInputPath(audioFeatherExtractJob, new Path(otherArgs[0]));
//    FileOutputFormat.setOutputPath(audioFeatherExtractJob, new Path(otherArgs[1]));
//    System.out.println("ExtractFeature:************************AudioFeatherExtractMap Is Done********************");
//    audioFeatherExtractJob.waitForCompletion(true);
    Configuration conf1 = new Configuration();
    String[] otherArgs1 = new GenericOptionsParser(conf1, args).getRemainingArgs();
    if (otherArgs1.length != 2) {
      System.err.println("Usage: ExtractFeature <in> <out>");
      System.exit(2);
    }
    Job imageFeatherExtractJob = new Job(conf1, "ExtractFeature");
    imageFeatherExtractJob.setJarByClass(ExtractFeature.class);
    imageFeatherExtractJob.setInputFormatClass(ImageInputFormat.class);
    imageFeatherExtractJob.setMapperClass(ImageFeatherExtractMap.class);
    imageFeatherExtractJob.setCombinerClass(ImageFeatherExtractReduce.class);
    imageFeatherExtractJob.setReducerClass(ImageFeatherExtractReduce.class);
    FileInputFormat.addInputPath(imageFeatherExtractJob, new Path(otherArgs1[0]));
    FileOutputFormat.setOutputPath(imageFeatherExtractJob, new Path(otherArgs1[1]));
    System.out.println("ExtractFeature:************************ImageFeatherExtractMap Is Done********************");
    System.exit(imageFeatherExtractJob.waitForCompletion(true) ? 0 : 1);
  }
}
